# Maintainer: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Stefan Wagner <stw@bit-strickerei.de>
pkgname=libmilter
_pkgname=sendmail
# This library is part of sendmail, but it does not share the version number with it.
# In order to find the right libmilter version number, check SMFI_VERSION definition
# that can be found in include/libmilter/mfapi.h (see also SM_LM_VRS_* defines).
# For example, version 1.0.1 has a SMFI_VERSION of 0x01000001.
pkgver=1.0.2
_pkgver=8.17.1
pkgrel=9
pkgdesc="Sendmail Mail Filter API (Milter)"
url="https://www.sendmail.com/sm/open_source"
arch="all"
options="!check"  # No independent test suite.
license="Sendmail"
makedepends="m4 linux-headers bsd-compat-headers"
subpackages="$pkgname-dev $pkgname-doc"
source="https://ftp.sendmail.org/$_pkgname.$_pkgver.tar.gz
	libmilter-sharedlib.patch
	default-pthread-stacksize.patch"
builddir="$srcdir/$_pkgname-$_pkgver"

prepare() {
	default_prepare

	cat >> devtools/Site/site.config.m4 <<-EOF
		dnl enable ipv6
		APPENDDEF(\`conf_libmilter_ENVDEF',\`-DNETINET6=1')
		dnl getipnodebyname/getipnodebyaddr is deprecated and not part of musl libc
		APPENDDEF(\`conf_libmilter_ENVDEF',\`-DNEEDSGETIPNODE=1')
	EOF
}

build() {
	make -C libmilter MILTER_SOVER=$pkgver
}

package() {
	mkdir -p "$pkgdir"/usr/lib
	make -C libmilter \
		INCOWN=root INCGRP=root INCMODE=644 \
		LIBOWN=root LIBGRP=root LIBMODE=644 UBINMODE=755 \
		MILTER_SOVER=$pkgver \
		DESTDIR="$pkgdir" \
		install

	install -m 644 -D libmilter/README \
		"$pkgdir"/usr/share/doc/$pkgname/README
	cp -r libmilter/docs "$pkgdir"/usr/share/doc/$pkgname/
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/license
}

sha512sums="
ae42343fb06c09f2db5d919d602afc4241914387dfdae0f15e0967dda3be25bf1d3a4637b57266763679646a3cea6aa07e6453266fd9b7358c1a09ec2b627a15  sendmail.8.17.1.tar.gz
31c36b57739946c1b9c7c85307fe5c53c45d7f8cbf427a0f2248db8b74871a6f5a30ef1af524915821aeca54310d28272bcd0a587cb918192214fa5c30e4a8da  libmilter-sharedlib.patch
d3e12943fe7e9babdf700a2d8c0229bc16fa2ea16097615600341dee13f137b157ffa4b03f76c92ba9c5552ca3bf01cb598f6a6201720408df3a37247001a219  default-pthread-stacksize.patch
"
